/*
 * Copyright © 2023 广州宏天软件股份有限公司 hotent
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hotent.project.auth.service;

import com.hotent.base.exception.CertificateException;
import com.hotent.base.jwt.JwtAuthenticationRequest;

import org.apache.http.client.ClientProtocolException;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Optional;

public interface AuthenticationService {
    /**
     * 登录系统，生成用户token
     * 
     * @param authenticationRequest 请求
     * @return 认证结果
     * @throws AuthenticationException
     * @throws CertificateException
     * @throws InvalidKeySpecException
     * @throws NoSuchAlgorithmException
     */
    ResponseEntity<?> createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest)
        throws AuthenticationException, CertificateException, InvalidKeySpecException,
        NoSuchAlgorithmException;

    /**
     * 刷新token
     * 
     * @param request 请求
     * @return token
     */
    ResponseEntity<?> refreshAndGetAuthenticationToken(HttpServletRequest request);

    /**
     * 退出登录
     * 
     * @param request 请求
     * @return
     */
    void signOut(HttpServletRequest request);

    /**
     * 单点登录系统
     * 
     * @param ticket
     * @param code
     * @param ssoMode
     * @param ssoUserId
     * @param service
     * @return 认证结果
     * @throws AuthenticationException
     * @throws ClientProtocolException
     * @throws IOException
     */
    ResponseEntity<?> ssoAuth(Optional<String> ticket, Optional<String> code, Optional<String> ssoMode, Optional<String> ssoUserId, String service)
        throws AuthenticationException, ClientProtocolException, IOException;

}
